/* eslint-disable import/no-extraneous-dependencies */
import { createApp } from 'vue';
import ElementPlus from 'element-plus';

import App from './App.vue';
import router from './router';

import 'element-plus/dist/index.css';

const app = createApp(App);
app.config.errorHandler = (error) => {
  console.log(error);
};
app.use(router).use(ElementPlus).mount('#app');

// 解决 ERROR ResizeObserver loop completed with undelivered notifications.
const debounce = (fn, delay) => {
  let timer = null;
  return (...args) => {
    const context = this;
    clearTimeout(timer);
    timer = setTimeout(() => {
      fn.apply(context, args);
    }, delay);
  };
};

const wResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends wResizeObserver {
  constructor(callback) {
    super(debounce(callback, 16));
  }
};
